package battleship.cxbr;

import java.util.ArrayList;

import battleship.emss.*;

public class HunterContext extends Context
{
	protected int x;
	protected int y;
	
	public HunterContext(String n,CxBRAgent a)
	{
		super(n,a);
	}
	
	//How to get here from above
	public double ParentRule(double Time)
	{
		
		return 0.0;
	}
	//How to get here from side
	public double SiblingRule(double Time)
	{
		return 0.3;
	}
	
	//Things to do when just entering
	public void Initialize(double Time)
	{
		x=512;
		y=512;
	}

	
	//What do actually do
	public void Action(double Time)
	{
		Agent.status.status=Name+" "+x+" "+y;
		Agent.actions.clear();
		
		//driving, and got there, go somewhere else
		if(Math.sqrt(Math.pow(Agent.status.x-x,2)+Math.pow(Agent.status.y-y,2))>5)
		{
			Agent.actions.add(new Move(Agent.status.x,Agent.status.y,x,y,3));
		}

		//detected others
		for(int i=0;i<Agent.detectedStatus.size();i++)
		{
			Status tmpStatus=Agent.detectedStatus.get(i);
			//not on my team, and a sub
			//And I am close enough
			//and it is alive
			
			if(tmpStatus.team!=Agent.status.team && tmpStatus.type==Agent.SUB && tmpStatus.alive==1)
			{
				Agent.status.status+=" Detect";
				//less than 30 miles off
				if(Math.sqrt(Math.pow(Agent.status.mx-tmpStatus.mx,2)+Math.pow(Agent.status.my-tmpStatus.my,2))<30*1600)
				{
					Agent.actions.add(new Fire(Agent.status.mx,Agent.status.my,tmpStatus.mx,tmpStatus.my,tmpStatus.name));
				}
			}
		}		
		
		Agent.incomingMessages.clear();
		return;
	}
	
}

